有什么简单的方法可以登录Android NDK代码吗?

您所在的位置:网站首页 Android ndk uid 有什么简单的方法可以登录Android NDK代码吗?

有什么简单的方法可以登录Android NDK代码吗?

2023-04-21 23:41| 来源: 网络整理| 查看: 265

百度翻译此文   有道翻译此文 问题描述

I'm looking for a way to easily debug C code in an Android NDK application using Eclipse. I've read ways to debug the app using gdb or something similar but what I want is a way to push messages to Eclipse somehow.

I'm looking for a solution that's as simple as using a print function in C and seeing it in the DDMS Log or anything similar. Does anyone have any experience doing this?

推荐答案

You can use the Android logging facilities:

#include #define APPNAME "MyApp" __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "The value of 1 + 1 is %d", 1+1);

Make sure you also link against the logging library, in your Android.mk file:

LOCAL_LDLIBS := -llog 其他推荐答案

No one has posted info about different log levels so far. The answer is an attempt to make the logging "picture" full.

#include #define TAG "MY_TAG" #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__) #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__) #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__) #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)

Usage:

char err[] = "wrong"; LOGE("Something went %s", err);

Link Android log library as below.

Android.mk:

LOCAL_LDLIBS := -llog

CMakeLists.txt:

find_library( log-lib log ) target_link_libraries( ${log-lib} )

Further reading: Logging

其他推荐答案

The easiest way is probably to redirect printf() statements to the system log (based on the "Viewing stdout and stderr" section of the official ADB reference manual.

Type these 3 commands on a command line:

adb shell stop adb shell setprop log.redirect-stdio true adb shell start

Then you can view the output of your "printf()" statements by looking at the "LogCat" window of Eclipse Debugger, or by typing this on a command line:

adb logcat

Just be aware that since the data is buffered before transferring from the emulator or device, you should definitely flush the stdout buffer, eg:

printf("Hello, I am %d years old!\n", 30); fflush(stdout);

You should then see a log message starting with "I/stdout:"



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3